package com.company.beauty.oss;

import com.company.beauty.oss.config.properties.OssProperties;
import com.company.pangu.aliyun.oss.client.OssClient;
import com.company.pangu.aliyun.oss.config.OssConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * <p>oss auto configuration</p >
 *
 * @author youyoukele
 * @version 1.0
 * @date 2024/04/22
 */
@Slf4j
@Import({OssProperties.class})
@Configuration(proxyBeanMethods = false)
public class OssAutoConfiguration {

    @Bean
    public OssClient ossClient(OssProperties properties){
        OssConfig config = OssConfig.builder()
                .accessKeyId(properties.getAccessKeyId())
                .accessKeySecret(properties.getAccessKeySecret())
                .regionId(properties.getRegionId())
                .endPoint(properties.getEndPoint())
                .cdnAddr(properties.getCdnAddr())
                .bucketName(properties.getBucketName())
                .roleArn(properties.getRoleArn())
                .roleSessionName(properties.getRoleSessionName())
                .build();
        log.info("nasa3 oss starter load oss client");
        return new OssClient(config);
    }

}
